#include  <cstdio>
#include  <iostream>
using namespace std;

long long arr[1600];

inline long long min(long long a, long long b)
{
	return a < b ? a : b;
}

int main(int argc, char *argv[])
{
	arr[1] = 1;
	long long a,b,c;
	a=b=c=1;

	for( int i = 2; i < 1501 ; ++i )
	{
		arr[i] = min(min(arr[a]*2,arr[b]*3),arr[c]*5);
		if(arr[i] == arr[a]*2) a++;
		if(arr[i] == arr[b]*3) b++;
		if(arr[i] == arr[c]*5) c++;

	}
	
	int n;
	scanf("%d",&n);
	while( n!=0 )
	{
		printf("%lld\n",arr[n]);
		scanf("%d",&n);
	}
}
